package com.d3works.apps.supplychain.web;

import com.d3works.apps.purchase.db.PurchaseRequest;
import com.d3works.apps.stock.service.StockLocationService;
import com.d3works.inject.Beans;
import com.d3works.rpc.ActionRequest;
import com.d3works.rpc.ActionResponse;

public class PurchaseRequestController {

  public void getStockLocation(ActionRequest request, ActionResponse response) {

    PurchaseRequest purchaseRequest = request.getContext().asType(PurchaseRequest.class);

    if (purchaseRequest.getCompany() != null) {

      response.setValue(
          "stockLocation",
          Beans.get(StockLocationService.class)
              .getDefaultReceiptStockLocation(purchaseRequest.getCompany()));
    }
  }
}
